#include <cmath>
#include <iostream>
using namespace std;
/**
 * 蒙哥马利幂模算法
 * 有 C^E mod N
 * 令 D = 1
 * 重复直到E = 0 :
 *     如果 E mod 2 == 0 :
 *         C = C * C mod N
 *         E = E / 2
 *     否则
 *         D = D * C mod N
 *         E = E - 1
 * 此时
*/
long long powerMod(long long C, long long E, long long N)
{
	long long D = 1;
	while (E != 0)
	{
		if (E & 1 != 1)
		{
			C = C * C & N;
			E /= 2;
		}
		else
		{
			D = D * C % N;
			E--;
		}
	}
	return D;
}
int main()
{
	long long a, b, c;
	cin >> a >> b >> c;
	// cout << (long long)pow(a, b) % c << endl;
	cout << powerMod(a, b, c); //TODO:TLE 30pts
	return 0;
}